import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
import * as path from 'path';
import * as express from 'express';

/**
 * 项目的启动函数
 *
 */
async function bootstrap() {
  // 创建主模块
  const app = await NestFactory.create(AppModule);

  // swagger生成api文档
  const options = new DocumentBuilder()
    .setTitle('CookBook Api')
    .setDescription('The API for cookbook app!')
    .setVersion('0.1')
    .addTag('cookbook')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('/swagger', app, document);

  // 添加静态资源代理
  app.use(express.static(path.join(__dirname, '../public')));
  app.set('views', path.join(__dirname, '../views'));
  app.set('view engine', 'pug');

  // 添加监听
  await app.listen(3000);
}

// 启动项目
bootstrap();
